package 二叉树;

//112 路径总和 DFS
public class Solution11 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        return dfs(root,targetSum,0);
    }
    boolean dfs(TreeNode root, int targetSum ,int cur){
        if(root==null) return false;
        cur+=root.val;
        if(cur==targetSum&&root.left==null&&root.right==null) return true;
        return dfs(root.left,targetSum,cur)||dfs(root.right,targetSum,cur);
    }
}
